/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.model;

/**
 * enum representing the available roles in application <code>Role</type>
 * 
 * @author Shyam Nair
 */
public enum Role
{
    /** enum representing ADMIN role */
    ADMINISTRATOR(1, "ADMIN"),

    /** enum representing PROFESSOR role */
    PROFESSOR(2, "PROF");

    /** attribute holding the role Id */
    private final Integer mRoleId;

    /** attribute holding the role Name */
    private final String mRoleName;

    /**
     * 
     * @param roleId
     * @param roleName
     */
    private Role(final Integer roleId, final String roleName)
    {
        mRoleId = roleId;
        mRoleName = roleName;
    }

    /**
     * @return Returns the mRoleName.
     */
    public String getRoleName()
    {
        return mRoleName;
    }

    /**
     * @return Returns the mRoleId.
     */
    public Integer getRoleId()
    {
        return mRoleId;
    }
    
    /**
     * <code>getRole(...)</code> method here
     * 
     * @param roleId
     * @return
     */
    public static Role getRole(final Integer roleId)
    {
        //check for null 
        if(roleId == null)
        {
            return null;
        }
        
        // iterate through all the role id 
        final Role[] roles = values();
        for(final Role role : roles)
        {
            final Integer roleIdTemp = role.getRoleId();
            // if matched return
            if(roleId.equals(roleIdTemp))
            {
                return role;
            }
        }
        // no match found return null
        return null;
    }
}
/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 9, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */